<template>
  <div class="background">
    <div class="main">
      <div class="new">
        <div class="h3">
          <h3>热门新碟</h3>
        </div>
        <ul class="hot-ul">
          <li
            class="forEach"
            v-for="albums in albums.slice(0, 10)"
            :key="albums.index"
          >
            <div>
              <span class="iconfont icon-bofang1"></span>
              <img :src="albums.blurPicUrl" alt="" />
            </div>
            <p class="artistName">{{ albums.name }}</p>
            <span class="name">{{ albums.artist.name }}</span>
          </li>
        </ul>
      </div>
      <div class="newHot">
        <div class="h3">
          <h3>全部新碟</h3>
          <p>全部</p>
          <span>|</span>
          <p>华语</p>
          <span>|</span>
          <p>欧美</p>
          <span>|</span>
          <p>韩国</p>
          <span>|</span>
          <p>日本</p>
        </div>
        <ul class="hot-ul">
          <li v-for="albums in albums.slice(0, pageSize)" :key="albums.index">
            <div>
              <span class="iconfont icon-bofang1"></span>
              <img :src="albums.blurPicUrl" alt="" />
            </div>
            <p>{{ albums.name }}</p>
            <span>{{ albums.artist.name }}</span>
          </li>
        </ul>
      </div>
      <div class="pagination">
        <el-pagination
          :page-size="pageSize"
          small
          background
          layout="prev, pager, next"
          :total="total"
          @prev-click="prevClick"
          @next-click="nextClick"
          @current-change="currentClick"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'NewDisc',
  data() {
    return {
      albums: [],
      total: 0, //总数
      currentPage: 0, //分页器页数
      pageSize: 10,
      newstore: 0 //最新数据
    }
  },
  async mounted() {
    /* const res = await this.$API.newdisc.reqGetHotDisc()
      console.log(res);
      console.log("albums",res.albums.blurPicUrl); */
    this.topalbum = await this.$API.newdisc.reqGetHotDisc()
    // console.log(this.topalbum)
    this.albums = this.topalbum.albums
    this.total = this.topalbum.total
  },
  methods: {
    async nextClick() {
      this.topalbum = await this.$API.newdisc.reqGetHotDisc()
      this.albums = this.topalbum.albums.slice(
        this.pageSize + 1,
        (this.newstore = this.pageSize + this.pageSize)
      )
      // console.log(1111)
    },
    async prevClick() {
      this.topalbum = await this.$API.newdisc.reqGetHotDisc()
      this.albums = this.topalbum.albums.slice(
        this.newstore - this.pageSize - this.pageSize,
        this.newstore - this.pageSize
      )
      //console.log(2222)
    },
    async currentClick(e) {
      console.log(e)
      this.topalbum = await this.$API.newdisc.reqGetHotDisc()
      this.albums = this.topalbum.albums.slice(
        e * this.pageSize - this.pageSize,
        e * this.pageSize
      )
    }
  }
}
</script>

<style scoped>
.background {
  width: 100%;
  background-color: #f5f1f1;
}
.main {
  width: 980px;
  margin: 0 auto;
  background-color: #fff;
  border-left: 1px solid #e0dddd;
  border-right: 1px solid #e0dddd;
  padding-bottom: 20px;
}
.h3 {
  margin: 0 40px;
  padding-top: 40px;
  width: 900px;
  border-bottom: 2px solid #c20c0c;
  margin-bottom: 30px;
  display: flex;
}
.newHot > .h3 {
  padding-top: 10px;
  width: 900px;
  border-bottom: 2px solid #c20c0c;
  margin-bottom: 30px;
  display: flex;
}
.h3 > h3 {
  font-size: 24px;
  font-weight: normal;
  height: 40px;
  padding-right: 5px;
}
.newHot .h3 > p {
  font-size: 14px;
  height: 14px;
  line-height: 40px;
  padding: 0 10px;
  cursor: pointer;
  color: #666;
}
.newHot .h3 > p:hover {
  text-decoration: underline;
}
.h3 > span {
  height: 14px;
  line-height: 40px;
  color: #c7c7c7;
}
.hot-ul > li {
  display: inline-block;
  padding: 0 0 30px 33px;
  list-style: none;
  width: 153px;
  overflow: hidden;
}
li:nth-child(5n) {
  padding-right: 33px;
}
.hot-ul {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  width: 980px;
}
.hot-ul > li:hover .iconfont {
  display: block;
}
.hot-ul > li > div > img {
  width: 153px;
  height: 130px;
}
.hot-ul > li > div {
  position: relative;
  cursor: pointer;
}
.hot-ul > li > div > span {
  font-size: 36px;
  position: absolute;
  top: 47px;
  right: 58px;
  display: none;
}
li > p {
  color: #000000;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}
li > span {
  color: #666666;
  font-size: 12px;
  cursor: pointer;
}
.pagination {
  text-align: center;
  padding: 20px 0;
}
li > span:hover {
  text-decoration: underline;
}
li > p:hover {
  text-decoration: underline;
}
</style>
